package com.duoduo.springcloud.service.impl;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.lang.generator.UUIDGenerator;
import com.duoduo.springcloud.service.IMessageProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;

/**
 * MessageProviderImpl
 *
 * @author qian
 * @version 1.0
 * @date 2020/12/1 14:17
 */
@EnableBinding(Source.class) //定义消息的推送管道
@Slf4j
public class MessageProviderImpl implements IMessageProvider {

    @Resource
    private MessageChannel output; //消息发送管道

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        return this.send(serial);
    }

    @Override
    public String send(String msg) {
        log.info("******serial:"+msg);
        return output.send(MessageBuilder.withPayload(msg).build())+"";
    }
}
